package com.lxq.springBoot.common;

import java.io.Serializable;

import org.springframework.util.StringUtils;

import com.alibaba.fastjson.JSON;

public class SerializeTool {

	public static String object2String(Object obj) {
		if (obj == null) {
			return null;
		}
		if (obj instanceof String) {
			return (String) obj;
		} else {
			return JSON.toJSONString(obj);
		}
	}

	public static <T extends Serializable> T getObjectFromString(String objBody, Class<T> clazz)

	{
		if (StringUtils.isEmpty(objBody)) {
			return null;
		}
		return JSON.parseObject(objBody, clazz);
	}

}
